package com.lineage.server.serverpackets;

import com.lineage.config.Config;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.templates.L1Account;
import com.lineage.server.world.World;
import java.util.Calendar;
import java.util.Iterator;
import java.util.TimeZone;

public class S_PacketBoxGm extends ServerBasePacket {
  private byte[] _byte;
  
  public static final int CALL_SOMETHING = 45;
  
  public S_PacketBoxGm(L1PcInstance srcpc, int mode) {
    this._byte = null;
    writeC(250);
    writeC(45);
    if (srcpc.isGm())
      callSomething(srcpc, mode); 
  }
  
  private void callSomething(L1PcInstance srcpc, int mode) {
    Iterator<L1PcInstance> itr = World.get().getAllPlayers().iterator();
    writeC(World.get().getAllPlayers().size());
    while (itr.hasNext()) {
      L1PcInstance pc = itr.next();
      L1Account acc = pc.getNetConnection().getAccount();
      if (acc == null) {
        writeD(0);
      } else {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(Config.TIME_ZONE));
        long lastactive = acc.get_lastactive().getTime();
        cal.setTimeInMillis(lastactive);
        cal.set(1, 1970);
        int time = (int)(cal.getTimeInMillis() / 1000L);
        writeD(time);
      } 
      writeS(String.valueOf(String.valueOf(mode)) + ":" + pc.getName());
      if (pc.isActived()) {
        writeS(String.valueOf(String.valueOf(String.valueOf(pc.getLevel()))) + "(挂)");
        continue;
      } 
      writeS(String.valueOf(pc.getLevel()));
    } 
    String xmode = null;
    switch (mode) {
      case 0:
        xmode = "删除已存人物保留技能";
        break;
      case 1:
        xmode = "移动座标至指定人物身边";
        break;
      case 2:
        xmode = "召回指定人物";
        break;
      case 3:
        xmode = "召回指定队伍";
        break;
      case 4:
        xmode = "全技能";
        break;
      case 5:
        xmode = "踢除下线";
        break;
      case 6:
        xmode = "封锁IP/MAC";
        break;
      case 7:
        xmode = "帐号封锁";
        break;
      case 8:
        xmode = "杀死指定人物";
        break;
    } 
    if (xmode != null) {
      srcpc.setTempID(mode);
      srcpc.sendPackets(new S_ServerMessage(166, "请注意目前模式为: " + xmode));
    } 
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
